#一CRUD
#1字符串增加 C
#1.1拼接
a = "x"
print(id(a))
a += "y"
print(id(a))
print(a)


#1.2插入
a = "ce"
a = a[0]+"d"+a[1]
print(a)


#2字符串检索 R
#2.1find
a ="abcde"
print(a.find("b"))
print(a.find("de"))
print(a.find("f"))


#2.2 index
a ="abcde"
print(a.index("b"))
print(a.index("de"))
# print(a.index("f"))


#2.3索引
a = "abcde"
print(a[0])
print(a[2:5])


#2.4startswith\endswith
a = "abcde"
print(a.startswith("a"))
print(a.startswith("b"))
print(a.endswith("e"))
print(a.startswith("f"))


#3更新U
#3.1 replace
a = "abcdea"
print(a.replace("a","m"))


#3.2 split and join
a = "ab cd ea"
print(a.split())
print(" ".join(a))


a = "ab?cd?ea"
print(a.split("?"))
b=a.split("?")
print("?".join(b))


#4删除 D
a = " ab@ca@ea "
print(a)
print(a.strip())
print(a.lstrip())
print(a.rstrip())
print(a.strip("a e"))


#二字符串格式化
print("{}-{}-{}".format(2020, 11, 6))
print("{0}-{1}-{0}".format("a", "b"))
print("{city}--{name}".format( name = "tianya",city = "Qingdao"))
city = "Qingdao"
print(f"{city} is nice")
print("{:.2f}".format(3.98765))


#三文件读写
a = open("第二周_第二节tmp.py", "r", encoding="utf-8")
b = open("第二周_第二节.py", "w", encoding= "utf-8")
b.write(a.read())
a.closed()
b.closed()